[−][src]Crate viaspf
A library implementing the Sender Policy Framework (SPF) protocol, version 1, as specified in RFC 7208.
This library contains a complete implementation of the SPF protocol.
However, no DNS resolution functionality is included in the library.
Instead, DNS resolution is abstracted into the trait Lookup
, an
implementation of which must be provided by library consumers when
initiating an SPF query.
Usage
The function evaluate_spf
is the main public API item. This function
corresponds to the check_host() abstraction RFC 7208, with the differences
in usage documented below.
fn evaluate_spf( lookup: &impl Lookup, config: &Config, ip: IpAddr, sender: &str, helo_domain: &str, ) -> QueryResult { // ... }
evaluate_spf
takes five arguments. The first two arguments, lookup
and
config
, control properties of protocol handling. The remaining arguments
ip
, sender
, and helo_domain
cover the inputs of the check_host()
function. The result type conveys the SPF result with additional diagnostic
information.
The lookup
argument is a reference of a type that implements
viaspf::Lookup
. This implementation must be provided by API
consumers; it functions as the core DNS resolution facility through which
all DNS queries are performed.
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use viaspf::*; struct MyLookup; impl Lookup for MyLookup { fn lookup_a(&self, name: &Name) -> LookupResult<Vec<Ipv4Addr>> { todo!() } fn lookup_aaaa(&self, name: &Name) -> LookupResult<Vec<Ipv6Addr>> { todo!() } fn lookup_mx(&self, name: &Name) -> LookupResult<Vec<Name>> { todo!() } fn lookup_txt(&self, name: &Name) -> LookupResult<Vec<String>> { todo!() } fn lookup_ptr(&self, ip: IpAddr) -> LookupResult<Vec<Name>> { todo!() } }
Once an implementation of Lookup
is available, authorising a host is
straightforward.
let lookup = MyLookup; let config = Default::default(); let result = evaluate_spf( &lookup, &config, Ipv4Addr::new(1, 2, 3, 4).into(), "amy@example.org", "mail.example.org" ); println!("spf={}", result.result);
More detailed information can be found at the doc strings for
evaluate_spf
and Lookup
, and elsewhere in this documentation.
Modules
model | A representation of SPF records and their constituent parts. |
trace | Tracing information gathered during SPF query execution. |
Structs
Config | An SPF query configuration object. |
ConfigBuilder | A builder for SPF query configuration objects. |
Name | A name that can be used in DNS queries. |
ParseNameError | An error indicating that a domain name could not be parsed. |
QueryResult | The result of evaluating an SPF query. |
Enums
ErrorCause | Errors that cause an SPF query to fail. |
EvalError | Errors that can occur during query evaluation. |
ExplanationString | An explanation of why a query evaluated to a |
LookupError | Errors that can occur when doing lookups. |
SpfResult | The result of an SPF evaluation. |
SpfResultCause | The cause that lead to an SPF result. |
Traits
Lookup | A trait for entities that perform DNS resolution. |
Functions
evaluate_spf | Performs an SPF query and evaluation. |
Type Definitions
LookupResult | A result type specialised for lookup errors. |